03 Java内存模型

public class SafeLazyInitialization {
	private static Instance instance;
	public synchronized static Instance getInstance() {
		if(instance == null)
			instance = new Instance();
		return instance;
	}
}
public class DoubleCheckedLocking {
	private static Instance instance;
	public static Instance getIntance() {
		if (instance == null) {
			synchronized (DoubleCheckedLocking.class) {
				if (instance == null)
					instance = new Instance();
			}
		}
		return instance;
	}
}
public class InstanceFactory {
	private static class InstanceHolder {
		public static Instance instance = new Instance();
	}

	public static Instance getInstance() {
		return InstanceHolder.instance;
	}
}


正在加载今日诗词....

📌 Powered by Obsidian Digital Garden and Vercel
载入天数...载入时分秒...